﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZEFIT
{
    public partial class NewCategoryForm : Form
    {
        Controller controller = null;
        WorkingCategory category = null;
        CategoriesForm cForm = null;

        public NewCategoryForm(CategoriesForm cForm)
        {
            this.cForm = cForm;
            InitializeComponent();
            controller = new Controller(new MYSQLAdapterWorkingCategory());
            category = new WorkingCategory();
        }

        public NewCategoryForm(CategoriesForm cForm, WorkingCategory category)
        {
            this.cForm = cForm;
            InitializeComponent();
            controller = new Controller(new MYSQLAdapterWorkingCategory());
            this.category = category;
            tbx_name.Text = category.Name;
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            category.Name = tbx_name.Text;
            controller.Save(category);
            cForm.dataLoad();
            this.Close();
        }

        private void tbx_name_TextChanged(object sender, EventArgs e)
        {
            if (tbx_name.Text != "")
            {
                btn_save.Enabled = true;
            }
            else {
                btn_save.Enabled = false;
            }
        }
    }
}
